<template>
  <div class="customerOverview-container">
    <div class="customerOverview-page">

      <el-card>
        <div>
          <el-button size="small" type="primary" @click="showTeiJian">新增推荐人</el-button>
        </div>
        <el-table :data="list" v-loading="listLoading" border style="width: 100%; margin: 20px 0">
          <el-table-column
            label="推荐人"
            align="center"
            min-width="100">
            <template slot-scope="scope">
                {{scope.row.introducerName}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="手机号"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.introducerMobile}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="推荐类型"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.introducerType}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="推荐时间"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.introducerTime}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="分成时长"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.commissionMonth}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="创建人"
            min-width="150">
            <template slot-scope="scope">
              {{scope.row.createUserName}}
            </template>
          </el-table-column>

          <el-table-column
            fixed="right"
            align="center"
            label="操作"
            min-width="150">
            <template slot-scope="scope">
                <el-button type="text" @click="delItem(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-container">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total, sizes,prev, pager, next,jumper"
            :page-size="listQuery.pageSize"
            :page-sizes="[10,15,20]"
            :current-page.sync="listQuery.pageNum"
            :total="count">
          </el-pagination>
        </div>
      </el-card>
    </div>
    <addTjr ref="addTjr" @getintroducerList="handleSearchList"></addTjr>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import {formatDate} from '@/utils/date';
import store from '@/store'
import {delCustomerIntroducer, addRelatio, delRelation,} from '@/api/partner'
import {developIntroduceList} from '@/api/company'
import addTjr from './addTjr'

const defaultListQuery={
  customerId:'',
  "pageNum" : 1,
  "pageSize" : 10
};

export default {
  name: "customerSycl",
  data(){
    return{
      roles:store.getters.roles ? store.getters.roles : [],
      list:[],
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      count: 0,
      listLoading: false,
      tjrList:[]
    }
  },
  components : {
    addTjr
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),

  },
  created() {

  },
  filters: {

  },
  methods:{
    init(customerId){
      this.listQuery.customerId = customerId;
      this.getList();
    },

    delItem(item){
      this.$confirm('确定删除此条记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delCustomerIntroducer({ciId:item.ciId}).then(()=>{
          this.getList();
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },


    showTeiJian(){
      this.$refs.addTjr.showTeiJian('add',this.listQuery.customerId)
    },

    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getList();
    },

    handleSearchList(){
      this.listQuery.pageNum = 1;
      this.getList();
    },
    //获取列表
    getList() {
      this.listLoading = true;
      developIntroduceList(this.listQuery).then(response => {
        this.list = response.list;
        this.count = response.count;
        this.listLoading = false;
      }).catch(()=>{
        this.listLoading = false;
      });
    },

  }
}
</script>

<style lang="scss">


</style>
